var JBridge = function(){

	var flag = false;

	return{

		callback:function(method, data){
			if(window.WebViewJavascriptBridge) {
				window.WebViewJavascriptBridge.callHandler(method, data);
			}
			else {
				document.addEventListener('WebViewJavascriptBridgeReady', function() {
					window.WebViewJavascriptBridge.callHandler(method, data);
				}, false);
			}
		},
		
		register:function(method, callback){
			if(window.WebViewJavascriptBridge){
				window.WebViewJavascriptBridge.registerHandler(method, callback);
			}
			else{
				document.addEventListener('WebViewJavascriptBridgeReady',function(event){
					if(!flag){
						window.WebViewJavascriptBridge.init(function(message, responseCallback) {//实例化事件
						});
						flag= true;
					}

					window.WebViewJavascriptBridge.registerHandler(method, callback);
				},false);
			}  
		}
	};
}();